/**
 * Created by tsy on 2016/10/27.
 */

function submitSearch() {
    $('#default_table').datagrid('load',{
        select_borrowNum: $('#select_borrowNum').val(),
        select_custName:$('#select_custName').val(),
        select_businessName:$("#select_businessName").val(),
        select_checkState: $('#select_checkState').val(),
        select_start_time:$('#select_start_time').datebox('getValue'),
        select_end_time:$("#select_end_time").datebox('getValue')
    });
}

function resetSearch()
{
    $("#select_borrowNum").textbox("setValue","");
    $("#select_custName").textbox("setValue","");
    $("#select_businessName").textbox("setValue","");
    $("#select_checkState").combobox("setValue","");
    $("#select_start_time").textbox("setValue","");
    $("#select_end_time").textbox("setValue","");
}

//		function formatAction(value,row,index)
//		{
//			var a = '<input type="button" value="详情" class="input" onclick="borrowapply_detail('+row.borrow_id+');">';
//			var b = '<input type="button" value="取消" class="input" onclick="borrowapply_cancel('+row.borrow_id+');">';
//			return a+'&nbsp;'+b;
//		}

function borrowapply_detail() {
    var obj=$("#default_table").datagrid('getSelected');
    //console.log($('#customer_table').datagrid('getPager').data("pagination").options.pageNumber);
    if(obj==null){
        alert("请选择借款订单！");
        return;
    }
    var borrow_id=obj.borrow_id;
    window.parent.addTab('借款申请详情','../../borrow/borrowapply/borrowapply_detail?borrow_id='+borrow_id);
}

//	申请取消动作
function borrowapply_cancel() {
    var obj=$("#default_table").datagrid('getSelected');
    //console.log($('#customer_table').datagrid('getPager').data("pagination").options.pageNumber);
    if(obj==null){
        alert("请选择借款订单！");
        return;
    }
    var borrow_id=obj.borrow_id;
    var msg = "您正在取消该笔借款申请，请输入取消原因：";
    var cont = "默认取消";
    var content = prompt(msg,cont);
    if (content)
    {
        var url = "../../borrow/borrowapply/borrowapply_cancel";
        var data = {"borrow_id":borrow_id,"content":content};
        $.ajax({
            type: "POST",
            async: true,
            data: data,
            url: url,
            success: function(d)
            {
                var dataObj = JSON.parse(d);
                var state = dataObj.state;
                var mes = dataObj.message;
                if(state == 1)
                {
                    alert(mes);
                    window.location.reload();
                }
                else
                {
                    alert(mes);
                    window.location.reload();
                }
            },
            error: function(e)
            {
                // alert(e);
                alert('网络错误，请联系程序员！');
            }
        });
    }
}

function format_remark(value,row,index){
    var supple_count=row.supple_count;
    if(supple_count!=null){
        return "有"+supple_count+"条备注信息";
    }else {
        return "";
    }
}